package com.zhuiyun.project.api.appusercancel.controller;

import com.zhuiyun.project.annotation.OptLog;
import com.zhuiyun.project.api.appusercancel.entity.userRecovery;
import com.zhuiyun.project.api.appusercancel.service.impl.AppUserCancelServiceImpl;
import com.zhuiyun.project.common.errorCode.CommonException;
import com.zhuiyun.project.common.response.CommonResult;
import com.zhuiyun.project.util.constants.CommonConstants;
import com.zhuiyun.project.util.pageUtil.PageRequest;
import com.zhuiyun.project.util.pageUtil.PageResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName AppUserController
 * Description T0D0
 * Author Administrator
 * @Date 2023/6/8
 * Version 1.0
 **/

@RestController
@RequestMapping("cancel")
@CrossOrigin
public class AppUserCancelController {
    @Autowired
    AppUserCancelServiceImpl appUserCancelServiceImpl;

    /**
     * 用户注销查询
     * @author 温
     * @date 2023/6/22 10:51
     * @parameter [userName, pageRequest]
     * @return com.zhuiyun.project.common.response.CommonResult
     */
    @GetMapping("/userCancelList")
    @ApiOperation(value = "用户注销查询")
    @OptLog(modular = "用户注销管理", type = CommonConstants.SELECT, describe = "用户注销")
    public CommonResult userCancelList(String userName, PageRequest pageRequest){
        PageResult pageResult = appUserCancelServiceImpl.userCancelList(userName, pageRequest);
        return CommonResult.ok(pageResult);
    }

    /**
     * 申请恢复用户注销的查询
     *
     * @return com.zhuiyun.project.common.response.CommonResult
     * @author 温
     * @date 2023/6/5 17:56
     * @parameter [nickName, pageRequest]
     */
    @GetMapping("/cancelList")
    @ApiOperation(value = "申请恢复账号查询")
    @OptLog(modular = "申请恢复账号管理", type = CommonConstants.SELECT, describe = "申请恢复账号查询")
    public CommonResult cancelList(PageRequest pageRequest) throws CommonException {
        // 调用分页方法
        PageResult PageResult = appUserCancelServiceImpl.cancelList( pageRequest);
        return CommonResult.ok(PageResult);
    }


    /**
     * 恢复用户注销
     *
     * @return
     * @author 温
     * @date 2023/6/15 8:51
     * @parameter
     */
    @DeleteMapping("/restoreUpdate/{restoreId}")
    @ApiOperation(value = "修改审核标识 恢复注销用户")
    @OptLog(modular = "用户注销管理", type = CommonConstants.UPDATE, describe = "恢复注销用户")
    public CommonResult restoreUpdate(@PathVariable("restoreId") int restoreId) {
        int i = appUserCancelServiceImpl.restoreUpdate(restoreId);
        return CommonResult.ok(i);
    }


    /**
     * 驳回注销账号恢复请求
     * @author 温
     * @date 2023/7/19 19:06
     * @parameter [userRecovery]
     * @return com.zhuiyun.project.common.response.CommonResult
     */
    @PostMapping("/recoverReason")
    public CommonResult recoverReason(@RequestBody  userRecovery userRecovery){
        int i = appUserCancelServiceImpl.recoverReason(userRecovery);
        return CommonResult.ok(i);
    }

    /**
     * 申请注销账号接口
     * @author 温
     * @date 2023/6/28 20:40
     * @parameter [userRecovery]
     * @return com.zhuiyun.project.common.response.CommonResult
     */
    @GetMapping("/RecoverAdd")
    public CommonResult RecoverAdd(Integer restoreId){
        int i = appUserCancelServiceImpl.RecoverAdd(restoreId);
        return CommonResult.ok(i);
    }

    /**
     * 彻底删除注销用户
     * @author 温
     * @date 2023/7/22 9:58
     * @parameter [cancellationId]
     * @return com.zhuiyun.project.common.response.CommonResult
     */
    @DeleteMapping("CancelDelete/{cancellationId}")
    public CommonResult CancelDelete(@PathVariable("cancellationId") Integer cancellationId ){
        int i = appUserCancelServiceImpl.CancelDelete(cancellationId);
        return CommonResult.ok(i);
    }

}



